#ifndef LONGKEY_COMMON_PCAGENT_COMMAND_LINE_VALIDATOR_H_
#define LONGKEY_COMMON_PCAGENT_COMMAND_LINE_VALIDATOR_H_

#include <Windows.h>
#include <map>
#include <atlstr.h>
#include "../base/basictypes.h"
#include "../base/scoped_ptr.h"

struct CommandLineArgs;
class CommandLineParser;
class CommandLineValidator;

// Validates all of the command line permutations for pcagent.exe
class PCAgentCommandLineValidator
{
public:
	typedef HRESULT (PCAgentCommandLineValidator::*ScenarioHandler)();
	typedef std::map<CString, ScenarioHandler> MapScenarioHandlers;
	typedef MapScenarioHandlers::iterator MapScenarioHandlersIter;

	PCAgentCommandLineValidator();
	~PCAgentCommandLineValidator();

	// Sets up the scenarios.
	HRESULT Setup();

	// Validates a pre-parsed parser against the scenarios and returns a
	// CommandLineArgs structure filled in with the proper values.
	HRESULT Validate(const CommandLineParser* parser, CommandLineArgs* args);

private:
	// Specific command-line scenario handlers.
	HRESULT OnNoArgs();
	HRESULT OnCore();
	HRESULT OnCrashHandler();
	HRESULT OnService();
	HRESULT OnMediumService();
	HRESULT OnServiceRegister();
	HRESULT OnServiceUnregister();
	HRESULT OnRegServer();
	HRESULT OnUnregServer();
	HRESULT OnNetDiags();
	HRESULT OnCrash();
	HRESULT OnComServer();
	HRESULT OnComBroker();
	HRESULT OnDemand();
	HRESULT OnInstall();
	HRESULT OnUpdate();
	HRESULT OnInstallHandoffWorker();
	HRESULT OnUpdateApps();
	HRESULT OnReportCrash();
	HRESULT OnReportCrashInteractive();
	HRESULT OnWebPlugin();
	HRESULT OnCodeRed();
	HRESULT OnRecover();
	HRESULT OnRecoverMachine();
	HRESULT OnUninstall();
	HRESULT OnRegisterProduct();
	HRESULT OnUnregisterProduct();
	HRESULT OnPing();

	void CreateScenario(const TCHAR* cmd_line, ScenarioHandler handler);

	HRESULT GetExtraAndAppArgs(const CString& switch_name);

	const CommandLineParser* parser_;
	CommandLineArgs* args_;
	scoped_ptr<CommandLineValidator> validator_;
	MapScenarioHandlers scenario_handlers_;

	DISALLOW_EVIL_CONSTRUCTORS(PCAgentCommandLineValidator);
};

#endif	// LONGKEY_COMMON_PCAGENT_COMMAND_LINE_VALIDATOR_H_